package jmine.tec.web.wicket.pages.validator;

import jmine.tec.web.wicket.WebWicketMessages;
import jmine.tec.web.wicket.exception.ValidationException;

import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.form.validation.IFormValidator;

import bancosys.tec.exception.LocalizedMessageHolder;

/**
 * Jmine base class for {@link org.apache.wicket.markup.html.form.validation.IFormValidator}s.
 * 
 * @author seiti
 * Jun 20, 2012
 */
public abstract class AbstractFormValidator implements IFormValidator {

    /**
     * Reports an error against the validatable using the specified LocalizedMessageHolder and associated args
     *
     * @param fc the formComponent to which associate this message
     * @param messageHolder the message holder
     */
    public void error(FormComponent<?> fc, LocalizedMessageHolder messageHolder)
    {
        if (fc == null) {
            throw new ValidationException(WebWicketMessages.VALIDATOR_FORM_COMPONENT_NEEDED_ATTACH_ERROR.create());
        }
        fc.error(messageHolder.getMessage());
    }
}
